package programs.statement;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;

import programs.expression.implementedClasses.Variable;

public abstract class BasicStatement extends Statement {

	@Override
	public abstract boolean isValidStatement();
	
	@Override
	public abstract boolean containsAction();
	
	@Override
	public abstract void assignGlobalVariable(Variable variable);
	
	public abstract void execute();
	
	@Override
	public abstract Set<Variable> getVariables();
	
	@Override
	public boolean isEmpty() {
		return false;
	}
	
	@Override
	public Iterator<BasicStatement> getIterator() {
		return new Iterator<BasicStatement>() {

			private boolean statementAlreadyReturned;
				
			public boolean hasNext() {
				return !statementAlreadyReturned;
			}

			public BasicStatement next() throws NoSuchElementException {
				if (!hasNext())
					throw new NoSuchElementException();
				statementAlreadyReturned = true;
				return BasicStatement.this;
			}

			public void remove() throws UnsupportedOperationException {
				throw new UnsupportedOperationException();
			}
			
		};
	}
}
